#include "widget.h"
#include "ui_widget.h"
#include <QTimer>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //设置初始值
    ui->lcdNumber->display(10);

    //创建一个QTimer
    timer = new QTimer(this);
    connect(timer, &QTimer::timeout, this, &Widget::func);
    timer->start(500);

}

Widget::~Widget()
{
    delete ui;
}

void Widget::func()
{
    int value = ui->lcdNumber->intValue();
    if(value-- <= 0)
    {
        timer->stop();
        return;
    }
    ui->lcdNumber->display(value);
}

